package com.jackyzgy.test.RMI;

import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.Naming;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.server.UnicastRemoteObject;

public class MyRemoteService extends UnicastRemoteObject implements RemoteService {

	protected MyRemoteService() throws RemoteException {
		super();
	}

	public User getUser(String userid) throws RemoteException {
		User user = new User();
		if("1".equals(userid)){
			user.setUsername("username1");
			user.setPassword("password1");
		}else if("2".equals(userid)){
			user.setUsername("username2");
			user.setPassword("password2");
		}
		return user;
	}  
	
	public static void main(String[] args) throws RemoteException, MalformedURLException, AlreadyBoundException {
		LocateRegistry.createRegistry(1099);  
        Naming.bind("rmi://127.0.0.1:1099/MyRemoteService", new MyRemoteService());  
        System.out.print("Service start"); 
	}
	
	public String getString() throws RemoteException {
		return "fdsfdsfds";
	}

	/* (non-Javadoc)
	 * @see com.jackyzgy.test.RMI.RemoteService#getUser1(com.jackyzgy.test.RMI.User)
	 */
	public User getUser1(User user) throws RemoteException {
		user.setPassword("111111");
		
		return user;
	}
    
}  